/*
 * @Descripttion:  
 * @version:  
 * @Author: chenxf
 * @Date: 2022-05-06 10:24:53
 */
import { getAction, putAction, postAction } from '@/api/manage'

import { serviceApi } from '@/api/common.js'

/**
 * 公共API接口
 */
export const api = {
  add: serviceApi.auth + '/departs',
  edit: serviceApi.auth + '/departs',
  delete: ids => serviceApi.auth + `/departs/${ids}`,
  deleteBatch: serviceApi.auth + '/departs/delete-batch',
  departTreeIds: serviceApi.auth + '/departs/trees/ids',
  listByOrgCode: orgCode => serviceApi.auth + `/departs/code/${orgCode}/addresses`
}

/**
 * 添加部门
 * @param params
 * @returns {AxiosPromise}
 */
export const addDept = params => postAction(api.add, params)

/**
 * 编辑部门
 * @param params
 * @returns {AxiosPromise}
 */
export const editDept = params => putAction(api.edit, params)

/**
 * 树结构形式加载所有部门的名称
 * @param params
 * @returns {AxiosPromise}
 */
export const queryIdTree = params => getAction(serviceApi.auth + '/departs/trees/ids', params)

/**
 * 通过关键字搜索部门信息
 * @param {*} params
 * @returns
 */
export const searchByKeywords = params => getAction(serviceApi.auth + '/departs/keywords', params)

/**
 * 树形结构加载
 * @param params
 * @returns {AxiosPromise}
 */
export const queryDepartTreeList = params => getAction(serviceApi.auth + '/departs/trees', params)

/**
 * 通过机构编码获取部门树
 * @param {*} orgCode
 * @param {*} params
 * @returns
 */
export const queryDepartByOrgCode = (orgCode, params) => getAction(api.listByOrgCode(orgCode), params)

/**
 * 获取部门角色权限
 * @param {*} params
 * @returns
 */
export const queryDeptRolePermission = (roleId, params) =>
  getAction(serviceApi.auth + `/departs/roles/permissions/${roleId}`, params)

/**
 * 指定部门用户列表
 * @param {*} departId
 * @param {*} params
 * @returns
 */
export const queryUserByDepId = (departId, params) => getAction(serviceApi.auth + `/departs/${departId}/users/list`, params)

/**
 * 树形结构加载异步
 * @param {*} params
 * @returns
 */
export const queryDepartTreeSync = (departId, params) => getAction(serviceApi.auth + `/departs/queryDepartTreeSync`, params)
